<template>
	<view class="mainpadding">
		<view class="textright margin_top6 ershiba xiaohui margin_right3" @click="jumphome">跳过 </view>
		<!-- <view class="textright ershiba xiaolan">完成 </view> -->
		<view class="xiaohei fonweight" style="font-size: 48rpx; margin-top: 120rpx;">最后一步啦，选择个人爱好</view>
		<view class="xiaohui strongtext" style="margin-top: 25rpx;">至少选3个，我们将根据你的选择推荐匹配的用户和内容</view>
		<view class=" flexleft flex_wrap margin_top6">
			<!-- 已选中 -->
			<view class="margin_top margin_right3" :class="item.ischeck?'yixbtn':'wexzbtn'" v-for="item in list" @click="checkitem(item)"
				:key="item.id">{{item.name}}</view>
		</view>
		<view class="flexcenter margin_top6">
			<!-- 未输入展示的按钮 -->
			<view class="margin_top6 denglhbtn flexcenter touming" v-if="allnum<3">完成</view>
			<!-- 已输入展示的按钮 -->
			<view class="margin_top6 denglhbtn flexcenter" v-if="allnum>=3" @click="tzxqsr">完成</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				list: [],
				allnum:0,
				ids:[]
			}
		},
		onLoad() {
			this.init()
		},
		watch: {
			list: {
				handler(newval) {
					let num = 0
					let ids = []
					this.list.forEach(item => {
						if (item.ischeck) {
							num = num +1
							ids.push(item.id)
						}
					})
					this.allnum = num
					this.ids = ids
				},
				deep: true
			}
		},
		methods: {
			checkitem(item){
				item.ischeck = item.ischeck?false:true
			},
			init() {
				httpRequest.request('/api/index/userFlag', 'GET', {}).then(res => {
					res.data.forEach(item=>{
						this.$set(item,"ischeck",false)
					})
					this.list = res.data
				})
			},
			tzxqsr() {
				uni.showLoading({
					mask:true,
					title:"请稍后"
				})
				httpRequest.request('/api/user/profile', 'GET', {
					user_flag_ids:this.ids.join()
				}).then(res => {
					uni.hideLoading()
					if(res.code==1){
						this.jumphome()
					}else{
						httpRequest.toast(res.msg)
					}
				})
			},
			jumphome(){
				uni.reLaunch({
					url:"/pages/homepage"
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.touming {
		opacity: 0.5;
	}

	.denglhbtn {
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: 800;
		color: #FFFFFF;
		width: 590rpx;
		height: 80rpx;
		background: #2361FF;
		border-radius: 52rpx;
	}

	.wexzbtn {
		padding: 18rpx 30rpx;
		background: #F7F7F7;
		border-radius: 36rpx;
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #000000;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.yixbtn {
		padding: 18rpx 30rpx;
		background: #2361FF;
		border-radius: 36rpx;
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
		display: flex;
		align-items: center;
		justify-content: center;
	}
</style>